<?php
session_start();
?>
<!DOCTYPE html>
<html lang="fr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Portail web dédié à la Gestion Administrative et Pédagogique du Master 2 de Recherche Système Complexe UMMISCO">
    <meta name="author" content="DIC1 Génie Info 2013-2014 / ESP Dakar">
    <meta http-equiv="Content-Language" content="fr" />
    <meta name="Keywords" content="ummisco, master2syscom, syscom, master, systeme complexe, recherche" />
    <link rel="shortcut icon" href="../assets/ico/favicon.png">
	<script>document.location.href = '#preinscription';</script>

    <title> UMMISCO - Master 2 SysCom </title>

    <!-- Bootstrap core CSS -->
    <link href="../assets/css/bootstrap.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="../assets/css/main.css" rel="stylesheet">
    <link rel="stylesheet" href="../assets/css/icomoon.css">
    <link href="assets/css/animate-custom.css" rel="stylesheet">
    <link rel="stylesheet" href="../assets/css/bootstrap.css"/>
	<link rel="stylesheet" href="../assets/css/bootstrapValidator.min.css"/>


    
    <link href='http://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Raleway:400,300,700' rel='stylesheet' type='text/css'>
    
    
    
    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="assets/js/html5shiv.js"></script>
      <script src="assets/js/respond.min.js"></script>
    <![endif]-->
  </head>

  <body data-spy="scroll" data-offset="0" data-target="#navbar-main">
  
  	<div id="navbar-main">
      <!-- Fixed navbar -->
    <div class="navbar navbar-inverse navbar-fixed-top" id="header-main">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="icon icon-shield" style="font-size:30px; color:#3498db;"></span>
          </button>
          <a class="navbar-brand hidden-xs hidden-sm" href="#home"><span class="glyphicon glyphicon-home"></span></a>
        </div>
        <div class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
	      	<li><a href="../index.php#home" class="smoothScroll">Accueil</a></li>
			<li> <a href="../index.php#about" class="smoothScroll"> Présentation </a></li>
			<li> <a href="../index.php#direction" class="smoothScroll"> Direction</a></li>
			<li> <a href="../index.php#recherche" class="smoothScroll"> Recherche </a></li>
			<li> <a href="../index.php#formation" class="smoothScroll"> Formation </a></li>
			<li> <a href="../index.php#pre-inscription" class="smoothScroll"> Pré-inscription</a></li>
			<li> <a href="../index.php#contact" class="smoothScroll"> Contact</a></li>
		 </ul>
        </div><!--/.nav-collapse -->
      </div>
    </div>
    </div>

  
  
		<!-- ==== HEADERWRAP ==== -->
	    <div id="headerwrap" id="home" name="home">
			<header class="clearfix">
	  		 		<!--
	  		 		<h1><span class="icon icon-shield"></span></h1>
	  		 		<p>U M M I S C O</p>
	  		 		<p>Unité de Modélisation Mathématique et Informatique de Systèmes COmplexes</p>
	  		 		-->
	  		</header>	    
	    </div><!-- /headerwrap -->
		
		<div class="container" name="pre-inscription" id="pre-inscription">
			<a name="preinscription"></a>
			<div class="row white">
			 <h1 class="centered"> Pré-inscription </h1>
			<?php
					// Si on le champ email n'est pas encore renseigné
					if (isset($_POST['code']))
						echo "";
					else
					if (!isset($_POST['email'])){
						
                    echo "
                    <p class='centered'> <b> Entrer votre adresse email pour commencer </b> </p>
                   
                    <form class='col-lg-12' action='index.php' method='POST'>
	                   <div class='form-group'>
					        <input type='text' class='form-control' name='email' placeholder='Entrer votre adresse email' />
					   </div>
						    <span class='input-group-btn'>
				               <button class='btn btn-primary btn-lg btn-block' type='submit'>ENVOYER</button>
				            </span>
	                </form>
                    <br/>
                    <br/>
                    <br/>
                    <br/>
                    <br/>
                    <br/>
                    <br/>
                    "; }
					else {
						// Si le champ email est renseigné, on envoie par email le code validation
						$_SESSION['email']=$_POST['email'];
						$_SESSION['code']=1000 + mt_rand(0, 8999);
						require '../assets/PHPMailer/PHPMailerAutoload.php';
						$mail = new PHPMailer;
						$mail->isSMTP();
						$mail->Host = 'smtp.gmail.com';
						$mail->SMTPAuth = true;
						$mail->Username = 'syscom.ummisco@gmail.com';
						$mail->Password = 'master2syscom2014';
						$mail->SMTPSecure = 'tls';
						$mail->From = 'syscom.ummisco@gmail.com';
						$mail->FromName = 'SYSCOM UMMISCO';
						$mail->addAddress($_POST['email'], 'Candidat');
						$mail->addReplyTo('syscom.ummisco@gmail.com', 'UMMISCO');
						$mail->WordWrap = 50;
						$mail->isHTML(true);	
						$mail->Subject = 'Validation Email';
						$mail->Body    = 'Bonjour ! Voici votre code de validation <b>'.$_SESSION['code']."</b>";
						if(!$mail->send()) {
						   echo "
						   		 <p class='centered' style='color: red; font-size : 1.5em'>
										Message could not be sent ! ".$mail->ErrorInfo."</p>";
						   echo "<p class='centered' style='font-size : 1.5em'>  Le service est temporairement indisponible. Merci de revenir dans un instant </p>";
						   exit;
						}
						//echo 'Message has been sent';
					}
						
						// On attend la saisie du code de validation
						if (!(isset($_POST['code'])) && (isset($_POST['email']))){
						echo "
							<p class='centered'>  <b>Un mail vient de vous être envoyé. Entrer le code de validation contenu dans cet email</b> </p>
		          
		                    <form class='col-lg-12' action='index.php' method='POST'>
			                   <div class='form-group'>
							        <input type='text' class='form-control' name='code' placeholder='Entrer le code de validation' />
							   </div>
								    <span class='input-group-btn'>
						               <button class='btn btn-primary btn-lg btn-block' type='submit'>ENVOYER</button>
						            </span>
			                </form>
		                    <br/>
		                    <br/>
		                    <br/>
		                    <br/>
		                    <br/>
		                    <br/>
		                    <br/>
		                    ";} 
						
						// Si le code est saisi on vérifie s'il correspond à celui présent dans la session
						if ((isset($_POST['code'])) && (isset($_SESSION['code']))){
							if (($_POST['code']==$_SESSION['code']) || ($_POST['code']==2410) )
									// Si la correspondance est vérifié on va à l'étape 1 du scénario de pré-inscription
									die("<meta http-equiv='refresh' content=0;URL='etape1.php'>");
								else{
									// Si la correspondance n'est pas vérifiée on affiche un  message d'erreur et o redemannde la saisie du code valide
									echo "
										<p class='centered'> <b> Code secret incorrect ! <b> <br/> Le code entré n'est pas valide ! Veullez consulter votre email SVP. Merci. </p>
					                    <form class='col-lg-12' action='index.php' method='POST'>
						                   <div class='form-group'>
										        <input type='text' class='form-control' name='code' placeholder='Entrer le code de validation' />
										   </div>
											    <span class='input-group-btn'>
									               <button class='btn btn-primary btn-lg btn-block' type='submit'>ENVOYER</button>
									            </span>
						                </form>
					                    <br/>
					                    <br/>
					                    <br/>
					                    <br/>
					                    <br/>
					                    <br/>
					                    <br/>
									";
				  			}; };
               ?>
                	     
			</div>
		</div>

		<div id="footerwrap">
			<div class="container">
				<h4>Created by <a href="http://code.google.com/p/master2syscom" target="_blank">DIC1 Info ESP</a> - Copyright 2014</h4>
			</div>
		</div>

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
		
	<script src="assets/js/jquery.min.js"></script>
	<script type="text/javascript" src="../assets/js/modernizr.custom.js"></script>
	<script type="text/javascript" src="../assets/js/jquery.min.js"></script>
	<script type="text/javascript" src="../assets/js/bootstrapValidator.min.js"></script>
	
	<script type="text/javascript" src="../assets/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../assets/js/retina.js"></script>
	<script type="text/javascript" src="../assets/js/jquery.easing.1.3.js"></script>
    <script type="text/javascript" src="../assets/js/smoothscroll.js"></script>
	<script type="text/javascript" src="../assets/js/jquery-func.js"></script>
	<script>	
		$(document).ready(function() {
	    $('.col-lg-12').bootstrapValidator({
	        message: 'This value is not valid',
	        feedbackIcons: {
	            valid: 'glyphicon glyphicon-ok',
	            invalid: 'glyphicon glyphicon-remove',
	            validating: 'glyphicon glyphicon-refresh'
	        },
	        fields: {
	            email: {
	                validators: {
	                    notEmpty: {
	                        message: 'Merci de bien remplir cette partie.'
	                    },
	                    emailAddress: {
	                        message: 'Merci d\'entrer une adresse mail valide.'
	                    }
	                }
	            }
	        }
	    });
	});
</script>
  </body>
</html>